
local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node or cc.CSLoader:createNode(Res.SpecTypeNode))
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end

function ClassRef.create(node)
	return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
	self.super.init(self, data)

    display.setCascadeOpacityEnabled(self._ui.Panel_1,true)
    display.setCascadeColorEnabled(self._ui.Panel_1,true)

    self:setSelected(false)
	display.uiAddClick(self._ui.Panel_1, function()
        if self._data and not self._isSelected then
    		executeFunc(self._onClick, self)
        end
	end)

	self:refresh()
end

-- data = SpecType
function ClassRef:refresh()
	if self._data then
		local specType = self._data

        self._ui.lock:setVisible(not specType:isOpen())
        self._ui.icon:loadTexture(specType:getIcon())
        self._ui.tlt:setString(specType:getNameDes())
        self._ui.tips:setString(specType:getShowDutyDes())
	end
end

function ClassRef:setSelected(b)
    self._isSelected = b
    self._ui.Panel_1:setOpacity(b and 255 or 255*0.4)
end

function ClassRef:isSelected()
    return self._isSelected
end

function ClassRef:setDotVisible(b)
	self._ui.dot:setVisible(b)
end

function ClassRef:onBtnClick(cb)
	self._onClick = cb
end

return ClassRef
